﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Reflection;

namespace TaoLeH.WebApi
{
    public class ApiService
    {
        public ApiService()
        {
            var methods = this.GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
            foreach (var methd in methods)
            {
                try
                {
                    if (Delegate.CreateDelegate(typeof(DelegateFactory.DoAction), this, methd.Name) is DelegateFactory.DoAction dl)
                        DelegateFactory.SetMethod(methd.DeclaringType.Name.Replace("Service", "") + "." + methd.Name, dl);
                }
                catch (ArgumentNullException anex)
                {
                    //LogHelper.Error("ApiService服务异常", anex.Message, anex);
                }
                catch (ArgumentException aex)
                {
                    //LogHelper.Error("ApiService服务异常", aex.Message, aex);
                }
            }
        }
    }
}
